package com.atzly.community.utils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * @author zlysimida
 * @date 2021/8/27 - 13:25
 */
public class CookieUtils {


    public static String getCookieTicket(HttpServletRequest request,String name){
        if(request == null || name == null){
            throw new IllegalArgumentException("用户参数不能为空!");
        }

        Cookie[] cookies = request.getCookies();
        if(cookies != null && cookies.length > 0){
            for (Cookie cookie : cookies) {
                if(cookie.getName().equals(name)){
                   return cookie.getValue();
                }
            }
        }
        return null;
    }
}
